package models

import "fmt"

type CommonResponse struct {
	ErrorCode interface{} `json:"errorCode"` //-1 indicat error ,0 indicat success
	ErrorMsg  string      `json:"errorMsg"`
	Data      interface{} `json:"data"`
}

// CheckSuccess 该方法为了兼容
func (c *CommonResponse) CheckSuccess() (bool, error) {
	switch c.ErrorCode.(type) {
	case int64:
		return c.ErrorCode.(int64) == 0, nil
	case string:
		return c.ErrorCode.(string) == "0", nil
	case float64:
		return c.ErrorCode.(float64) == 0, nil
	default:
		return false, fmt.Errorf("CommonResponse checkSuccess fail, CommonResponse:%++v ", c)
	}
}
